package com.fidku 
{
	import com.deezer.DeezerMobile
	import com.deezer.objects.Artist
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.media.StageWebView;
	
	/**
	 * Deezer API AS3 Example
	 * @author Patricio Cornejo
	 * @link http://fidku.com
	 */
	public class Example extends Sprite 
	{
		private const apiKey:String = ""; //api ID
		private const secretKey:String = "";
		private const redirectUri:String = "";
		private const perms:Array = ["basic_access", "email"];
		
		private var swv:StageWebView;
		
		public function Example():void
		{
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			button.addEventListener(MouseEvent.CLICK, clickButton);
		}
		
		public function clickButton(e:MouseEvent):void
		{
			trace("clickButton");
			DeezerMobile.auth(authReady, getSWV(), apiKey, secretKey, redirectUri, perms);
		}
		
		private function authReady(response:Object):void 
		{
			if (response.success) {
				//User.byId(userReady, "me");
				//Artist.byId(artReady, 27);
				//Artist.albums(artReady, 27);
			}
		}
		
		private function artReady(response:Object):void 
		{
			trace(JSON.stringify(response));
		}
		
		private function userReady(response:Object):void 
		{
			trace(JSON.stringify(response));
		}
		
		private function getSWV():StageWebView
		{
			if (!swv) {
				swv = new StageWebView();
				swv.stage = this.stage;
				swv.viewPort = new Rectangle(0, 0, stage.fullScreenWidth, stage.fullScreenHeight);
			}
			
			return swv;
		}
		
	}

}